import {Http} from "../utils/http"

class Category {
    roots = []
    allCategories = []
    currentRoot = null
    currentRootSubs = []

    async getAll() {
        const data = await Http.request({
            url: `category/all`
        })

        debugger
        this.roots = data.roots;
        this.allCategories = data.subList;
        this.currentRoot = data.currentCategory;
        this.currentRootSubs = data.currentSubList;
    }

    getRoots() {
        return this.roots
    }

    getCurrentRoot() {
        return this.currentRoot
    }

    getCurrentSubs() {
        return this.currentRootSubs
    }

    getRoot(rootId) {
        debugger
        return this.roots.find(r=>r.id == rootId)
    }

    getSubs(parentId) {
        return this.allCategories[parentId]
    }
}

export {
    Category
}